package com.graduation.fq.student.Logic;

import com.graduation.fq.student.Args.SimpleEventArgs;
import com.graduation.fq.student.Process.ChooseProcess;
import com.graduation.fq.student.Utils.ChooseUrlIndex;
import com.graduation.fq.student.interfaces.EventListener;
import com.graduation.fq.student.interfaces.ResponseListener;

/**
 * Created by jifang
 * Time 2016/5/27 15:28.
 */
public class ChooseLogic extends BaseLogic {

    private static ChooseLogic instance;

    public static ChooseLogic getInstance() {
        if (instance == null) {
            instance = new ChooseLogic();
        }
        return instance;
    }

    public void isAdded(Integer uId, Integer cId, final EventListener listener) {
        final ChooseProcess process = new ChooseProcess(ChooseUrlIndex.IS_ADDED, uId, cId);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                SimpleEventArgs<Boolean> args = new SimpleEventArgs<>(process.getStatus(), process.is_added());
                fireEvent(args, listener);
            }
        });
    }

    public void add(Integer uId, Integer cId) {
        new ChooseProcess(ChooseUrlIndex.ADD, uId, cId).runGet();
    }

    public void cancel(Integer uId, Integer cId) {
        new ChooseProcess(ChooseUrlIndex.CANCEL, uId, cId).runGet();
    }
}
